package com.mbs.project.mbs.mbinfo.service.impl;

import java.util.List;

import com.mbs.common.utils.DateUtils;
import com.mbs.common.utils.text.Convert;
import com.mbs.project.mbs.dispose.domain.MessageBoardDispose;
import com.mbs.project.mbs.dispose.mapper.MessageBoardDisposeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mbs.project.mbs.mbinfo.mapper.MessageBoardInfoMapper;
import com.mbs.project.mbs.mbinfo.domain.MessageBoardInfo;
import com.mbs.project.mbs.mbinfo.service.IMessageBoardInfoService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 留言板Service业务层处理
 *
 * @author xyl
 * @date 2022-01-25
 */
@Service
public class MessageBoardInfoServiceImpl implements IMessageBoardInfoService {
    @Autowired
    private MessageBoardInfoMapper messageBoardInfoMapper;
    @Autowired
    private MessageBoardDisposeMapper messageBoardDisposeMapper;

    /**
     * 查询留言板
     *
     * @param mbId 留言板ID
     * @return 留言板
     */
    @Override
    public MessageBoardInfo selectMessageBoardInfoById(Long mbId) {
        return messageBoardInfoMapper.selectMessageBoardInfoById(mbId);
    }

    /**
     * 查询留言板列表
     *
     * @param messageBoardInfo 留言板
     * @return 留言板
     */
    @Override
    public List<MessageBoardInfo> selectMessageBoardInfoList(MessageBoardInfo messageBoardInfo) {
        return messageBoardInfoMapper.selectMessageBoardInfoList(messageBoardInfo);
    }

    /**
     * 新增留言板
     *
     * @param messageBoardInfo 留言板
     * @return 结果
     */
    @Transactional
    @Override
    public int insertMessageBoardInfo(MessageBoardInfo messageBoardInfo) {
        messageBoardInfo.setCreateTime(DateUtils.getNowDate());
        int i = messageBoardInfoMapper.insertMessageBoardInfo(messageBoardInfo);
        MessageBoardDispose mbd = new MessageBoardDispose();
        mbd.setDisposeStatus(0);
        mbd.setMbId(messageBoardInfo.getMbId());
        mbd.setCreateTime(DateUtils.getNowDate());
        int i1 = messageBoardDisposeMapper.insertMessageBoardDispose(mbd);
        return i + i1;
    }

    /**
     * 修改留言板
     *
     * @param messageBoardInfo 留言板
     * @return 结果
     */
    @Override
    public int updateMessageBoardInfo(MessageBoardInfo messageBoardInfo) {
        messageBoardInfo.setUpdateTime(DateUtils.getNowDate());
        return messageBoardInfoMapper.updateMessageBoardInfo(messageBoardInfo);
    }

    /**
     * 删除留言板对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteMessageBoardInfoByIds(String ids) {
        return messageBoardInfoMapper.deleteMessageBoardInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除留言板信息
     *
     * @param mbId 留言板ID
     * @return 结果
     */
    @Override
    public int deleteMessageBoardInfoById(Long mbId) {
        return messageBoardInfoMapper.deleteMessageBoardInfoById(mbId);
    }
}
